/**
 * UEditorController.java
 * @author: lhb
 * 2017年8月11日 下午3:42:14
 */
package com.yt.Controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.yt.Service.UserService;
import com.yt.entity.User;

/**
 * @author lhb456465
 *
 */
@Controller  
@RequestMapping("/UEditor")  
public class UEditorController {
	@Resource
	UserService userService;
	
	

	 
	 @RequestMapping("/Go")  
	 private String GoUEditor(HttpServletRequest request){
	String url=request.getContextPath().split("Maven_SSM")[0]+"upload/NewPictures/";		 
		System.out.println(request.getContextPath() + "/attached/");
		System.out.println(url);
		
			return "Test";
		 }
	 
	  @RequestMapping("/bjq")  
		 private String Login(User user,HttpServletRequest request,Model model){

			//model.addAttribute("user", userLg);
			return "user/index";
		 }
	  
	  
	  //测试页面
	  @RequestMapping("/tj")  
		 private String Testtj(HttpServletRequest request,String content,Model model){
		// System.out.println(content);
		  String html = content;
		  Document document = Jsoup.parse(html);
		  Elements html1=document.select("img").attr("style", "width: 100%").parents();
		  StringBuffer sb=new StringBuffer();
		   sb.append(html1.toString());
		   String k=sb.toString();
		   String u=document.toString().split("<body>")[1].split("</body>")[0];
			//获取指定class的内容指定tag的元素
			String conn="";
			Elements liElements = document.getElementsByTag("p");
			for (int i = 0; i < liElements.size(); i++) {
			   // System.out.println(i + ". " + liElements.get(i).text()+"\r\n");
			     String con="    "+liElements.get(i).text()+"\r\n";
			     conn+=con;
			}
		  System.out.println("con:"+conn);
		  userService.saveURL(u);
		  model.addAttribute("content", content);
		  return "user/index";
		 }
	  
	  
	  //取页面
	  @RequestMapping("/getURL")  
	  private String getURL(String id,Model model,User user){
		     User user1=userService.getURL(id);
			
			model.addAttribute("user1", user1);
			
			
//			Map<String,Object> map = new HashMap<String, Object>();
//			map.put("list", list);
			return "MyJsp";
		 }
	  
	  
	  
	  
	  
	 
	 

}
